package com.jj.controller;

import com.jj.pojo.Dept;
import com.jj.pojo.Emp;
import com.jj.pojo.Result;
import com.jj.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/depts")
public class DeptController {
    @Autowired
    private DeptService deptService;
//    根据ID查询部门信息
    @GetMapping("/{id}")
    public Result select(@PathVariable Integer id){
        log.info("根据ID查询部门信息:{}",id);
        List<Dept> deptList = deptService.select(id);
        return Result.success(deptList);
    }
//    根据ID删除部门信息
    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable Integer ids){
        log.info("根据ID删除部门信息:{}",ids);
        deptService.delete(ids);
        return Result.success();
    }
//    添加部门信息
    @PostMapping
    public Result insert(@RequestBody Dept dept){
        log.info("添加部门信息:{}",dept);
        deptService.insert(dept);
        return Result.success();
    }
//    修改部门信息
    @PutMapping
    public Result update(@RequestBody Dept dept){
        log.info("修改部门信息:{}",dept);
        deptService.update(dept);
        return Result.success();
    }
@GetMapping
    public Result selete1(Dept dept){
        log.info("查询部门信息:{}",dept);
        List<Dept> listdept = deptService.select1(dept);
        return Result.success(listdept);
    }

}
